package ${packageName};

<%
if (hasDateType) {
    println("import com.fasterxml.jackson.annotation.JsonFormat;");
    println();
    if (java8) {
        println("import java.time.LocalDateTime;");
    } else {
        println("import java.util.Date;");
    }
}
%>

<%
if (hasKeywords) {
    println("import javax.persistence.Column;");
}
%>
import javax.persistence.Entity;
<%
if (!isEmpty(primaryKeys)) {
    println("import javax.persistence.Id;");
}
%>
import javax.persistence.Table;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;

@Entity
@Table(name = "${tableName}")
public class ${className} {

    <%
    for (field in fields) {
        println("    public static final String " + strutil.toUpperCase(field.columnName) + " = \"" + field.name + "\";");
    }
    %>

    <%
    for (field in fields) {
        if (field.primaryKey) {
            println("    @Id");
        }
        if (field.keyword) {
            println("    @Column(name = \"" + field.columnName + "\")");
        }
        if (field.type == 'Date') {
            println("    @JsonFormat(pattern = \"yyyy-MM-dd HH:mm:ss\", timezone = \"GMT+8\")");
        }
        println("    private " + field.type + " " + field.name + "; // " + field.columnName);
        println();
    }
    for (field in fields) {
        println("    public void " + field.setterName + "(" + field.type + " " + field.name + ") {");
        println("        this." + field.name + " = " + field.name + ";");
        println("    }");
        println();
        println("    public " + field.type + " " + field.getterName + "() {");
        println("        return this." + field.name + ";");
        println("    }");
        println();
    }
    %>
    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }

    @Override
    public boolean equals(Object obj) {
        return EqualsBuilder.reflectionEquals(this, obj);
    }

    @Override
    public int hashCode() {
        return HashCodeBuilder.reflectionHashCode(this);
    }

}